﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using System.ComponentModel;

namespace BDSim
{
    /// <summary>
    /// 用户段模型基类
    /// </summary>
    [TypeConverter(typeof(PropertySorter))]
    public class UserBaseModel : BDSimObject
    {
        #region 字段
        ObservableCollection<CReceiver> _RecCollection = new ObservableCollection<CReceiver>();
        private EUserType _Type;
        
        private UTCTime _CurT;
        private UTCTime _InitT;
        private NodePosVel _PosVelXYZ=new NodePosVel();//真实位置：CGCS2000坐标系中的直角坐标
        private BLH_PosVel _PosVelBLH=new BLH_PosVel();//真实位置CGCS2000坐标系中的大地坐标
        private Attitude _UserAttitude = new Attitude();//载体姿态数据
        private NodePosVel _FixedPosVelXYZ=new NodePosVel();//当前时刻的定位结果：CGCS2000坐标系中的直角坐标
        private BLH_PosVel _FixedPosVelBLH = new BLH_PosVel();//当前时刻的定位结果：CGCS2000坐标系中的大地坐标
        private MeteorologicalsParamClass _MeteParamClass=new MeteorologicalsParamClass();
        private EWayToGetMeteorological _WayToGetMeteorological;

        //[XmlIgnore,Browsable(false)]
        public MeteorologicalsParam MeteParam=new MeteorologicalsParam();//用户的气象参数
        
        #endregion 字段

        #region 属性
        /// <summary>
        /// 用户类型，包括静态、汽车、飞机、轮船、弹道、航天器、自定义用户
        /// </summary>
        [XmlAttribute, DescriptionAttribute("用户载体类型"), CategoryAttribute("基本信息"), ReadOnly(true), PropertyOrder(1)]
        public EUserType Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        [XmlAttribute, DescriptionAttribute("用户名称"), CategoryAttribute("基本信息"), PropertyOrder(2)]
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value; NotifyPropertyChanged("Name");
            }
        }

        /// <summary>
        /// 真实位置：CGCS2000坐标系中的直角坐标
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public NodePosVel PosVelXYZ
        {
            get { return _PosVelXYZ; }
            set { _PosVelXYZ = value; }
        }

        /// <summary>
        /// 真实位置CGCS2000坐标系中的大地坐标
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public BLH_PosVel PosVelBLH
        {
            get { return _PosVelBLH; }
            set { _PosVelBLH = value; }
        }

        /// <summary>
        /// 载体姿态
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public Attitude UserAttitude
        {
            get { return _UserAttitude; }
            set { _UserAttitude = value; }
        }

        /// <summary>
        /// 气象参数的获取方法，包括读文件、界面设置两种方式
        /// </summary>
        [XmlAttribute, DescriptionAttribute("气象参数来源控制，包括界面直接输入、文件读取两种方式"), CategoryAttribute("气象参数"), PropertyOrder(1)]
        public EWayToGetMeteorological WayToGetMeteorological
        {
            get
            {
                return _WayToGetMeteorological;
            }
            set
            {
                _WayToGetMeteorological = value;

                switch (_WayToGetMeteorological)
                {
                    case EWayToGetMeteorological.EGNOSModel:
                        PropertyFieldControl.SetPropertyVisibility(this, "MeteParamClass", false);
                        break;
                    case EWayToGetMeteorological.用户输入:
                        PropertyFieldControl.SetPropertyVisibility(this, "MeteParamClass", true);
                        break;

                }
                DisplayObjectProperty(this);
            }
        }

        /// <summary>
        /// 气象参数
        /// </summary>
        [Browsable(false), DescriptionAttribute("气象参数，依次为"), CategoryAttribute("气象参数"), PropertyOrder(2)]
        public MeteorologicalsParamClass MeteParamClass
        {
            get
            {
                return _MeteParamClass;
            }
            set
            {
                _MeteParamClass = value;
            }
        }

    

        /// <summary>
        /// 当前时间
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public UTCTime CurT
        {
            get
            {
                return _CurT;
            }
            set
            {
                _CurT = value;
            }
        }

        /// <summary>
        /// 初始时间
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public UTCTime InitT
        {
            get
            {
                return _InitT;
            }
            set
            {
                _InitT = value;
            }
        }

        /// <summary>
        /// CGCS2000直角坐标系下的定位结果
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public NodePosVel FixedPosVelXYZ
        {
            get
            {
                return _FixedPosVelXYZ;
            }
            set
            {
                _FixedPosVelXYZ = value;
            }
        }

        /// <summary>
        /// CGCS2000大地坐标系下的定位结果
        /// </summary>
       [XmlIgnore, Browsable(false)]
        public BLH_PosVel FixedPosVelBLH
        {
            get
            {
                return _FixedPosVelBLH;
            }
            set
            {
                _FixedPosVelBLH = value;
            }
        }

        /// <summary>
        /// 接收机对象列表
        /// </summary>
        [Browsable(false)]
        public ObservableCollection<CReceiver> RecCollection
        {
            get { return _RecCollection; }
            set { _RecCollection = value; NotifyPropertyChanged("RecCollection"); }
        }

        #endregion 属性

        #region 所属地面段
        UserSegment _Parent;

        [XmlIgnore, Browsable(false)]
        public UserSegment Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }
        #endregion

        #region 方法
        public void GetMeteorological(UTCTime CurTime)
        {
            if (EWayToGetMeteorological.EGNOSModel == WayToGetMeteorological)
            {
                MeteParam = ClimateSimModel.GetClimatePara(CurTime, PosVelBLH, true);

            }
            else
            {
                MeteParam = MeteParamClass.ToStruct();
            }
 
        }
        #endregion 方法

    }
}
